// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/**
 * @brief
 *
 * @version  0.1
 * @author   yuanchenxi
 * @date     2024.12.20
 */

#include "Import/BDFImport/BulkData/Dynamic/TICParser.h"

#include <algorithm>
#include <cstdint>
#include <iostream>

#include "boost/algorithm/string.hpp"

#include "Utility/Logging/SGLogger.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Dynamic/ITICService.h"

#include "Import/BDFImport/BDFParserBase.h"

BULKDATA_ENTRY_PARSER_REG (TIC);

using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure;

/*
// file://./../../Doc/MarkDown/BulkData/TIC/TIC.md>
*/

// 以下需要修改
enum TICIndex : std::uint8_t
{
    TICIndex_SID = 1,
    TICIndex_G   = 2,
    TICIndex_C   = 3,
    TICIndex_U0  = 4,
    TICIndex_V0  = 5,
};
SG::DataStructure::Common::Status BDF::BULKDATA::ParseTIC (const std::shared_ptr<SG::DBManager::DBServiceFactory>& dbServiceFactory,
                                                           std::vector<std::string>&                               dividedEntryInfo)
{
    SG::DataStructure::FEM::TICData tempTIC;

    tempTIC.m_domainId = 1;

    std::string curStrKey;
    for (size_t i = 1; i < 9; i++)
    {
        curStrKey          = dividedEntryInfo[i];
        bool const isEmpty = is_all_space (curStrKey);
        if (isEmpty)
        {
            continue;
        }

        switch (i)
        {
        case TICIndex_SID:
            tempTIC.m_sId = convertToI64 (curStrKey);
            break;
        case TICIndex_G:
            tempTIC.m_G = convertToI64 (curStrKey);
            break;
        case TICIndex_C:
            tempTIC.m_C = convertToI64 (curStrKey);
            break;
        case TICIndex_U0:
            tempTIC.m_U0 = convertToReal (curStrKey);
            break;
        case TICIndex_V0:
            tempTIC.m_V0 = convertToReal (curStrKey);
            break;
        default:
            break;
        }
    }
    return dbServiceFactory->get<ITICService> ()->Add (tempTIC);
}